#ifndef __SIMPLE_LINEAR__
#define __SIMPLE_LINEAR__

#include "Bin.h"

template <class T, T _NULL_VALUE>
class SimpleLinear {
private:
	const int						_RANGE;
	Bin<T,_NULL_VALUE>* const	_pqueue;

public:
	SimpleLinear(int newRange) : _RANGE(newRange), _pqueue( new Bin<T,_NULL_VALUE>[_RANGE] ) {
	}

	~SimpleLinear() {
		delete[] _pqueue;
	}

	bool add(T item,int key) {
		_pqueue[key].put(item);
		return true;
	}

	T removeMin() {
		for(int i=0;i<_RANGE;++i) {
			T item=_pqueue[i].get();
			if(_NULL_VALUE != item)
				return item;
		}
		return _NULL_VALUE;
	}

	T peek() {
      T item;
      for(int i=0;i<_RANGE;++i) {
			item=_pqueue[i].peek();
			if(_NULL_VALUE != item)
				return item;
		}
      return _NULL_VALUE;
	}

	void clear() {
		for(int i=0;i<_RANGE;++i)
			_pqueue[i].clear();
	}

	bool isEmpty() {
		return _NULL_VALUE == peek();
	}

	int size() {
		int result=0;
		for(int i=0;i<_RANGE;++i)
			result+=_pqueue[i].size();
		return result;
	}

	bool sanityCheck() {
		return true;
	}

private:
	SimpleLinear(const SimpleLinear& other);
	SimpleLinear& operator=(const SimpleLinear& other);
};

#endif
